package com.cqndt.disaster.device.controller;

import javax.servlet.http.HttpServletRequest;
import com.cqndt.disaster.device.util.AjaxResult;
import org.springframework.web.bind.annotation.*;
import com.cqndt.disaster.device.vo.TabReportFileVo;
import com.cqndt.disaster.device.vo.TabDocCollection;
import com.cqndt.disaster.device.service.AppTabProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import com.cqndt.disaster.device.service.AppTabReportingFileService;

/**
 * @author lgb
 * @date 2020-9-1
 * @return 项目文档
 **/
@RestController
@RequestMapping(value="/api/v2")
public class TabDocController extends BaseController {

    @Autowired
    private AppTabReportingFileService tabReportingFileService;
    @Autowired
    private AppTabProjectService appTabProjectService;

    /**
     * @param request 
     * @param uploadMonth 查询月份
     * @param uploadYear 查询年份
     * @param projectId 项目id
     * @param fileType 报表类型
     * @param page 页数
     * @param limit 条数
     * @return 根据项目id获取报表
     **/
    @RequestMapping(value="/report",method=RequestMethod.POST)
    public AjaxResult getAllReportByCondition(HttpServletRequest request,
    		TabReportFileVo vo){
        String userId = request.getHeader("id");
        StringBuffer searchTime = new StringBuffer();
        if(null != vo.getUploadYear() && !("").equals(vo.getUploadYear())){
            searchTime.append(vo.getUploadYear());
        }
        if(null != vo.getUploadMonth() && !("").equals(vo.getUploadMonth())){
            searchTime.append("-"+vo.getUploadMonth());
        }
        vo.setSearchTime(searchTime.toString());
        vo.setUserId(userId);
        TabDocCollection collection = tabReportingFileService.listReportingFile(vo);
        return entityResult(collection,"获取报表列表");
    }
    /**
     * @param projectId 项目id
     * @return 根据项目id查询项目文档
     **/
    @PostMapping(value="/data")
    public AjaxResult getTabProjectDatum(Integer projectId){
        return entityResult(appTabProjectService.selectProjectDatum(projectId),"项目文档");
    }

    /**
     * @param request
     * @param projectId 项目id
     * @return 根据项目id查询图片
     **/
    @PostMapping(value="/picture")
    public AjaxResult getTabProjectPicture(HttpServletRequest request,Integer projectId){
        String userId = request.getHeader("id");
        return entityResult(appTabProjectService.selectAttachmentImgs(projectId,userId),"项目图片");
    }
    /**
     * @param request
     * @param projectId 项目id
     * @return 根据项目id查询视频
     **/
    @PostMapping(value="/video")
    public AjaxResult getTabProjectVideo(HttpServletRequest request,Integer projectId){
        String userId = request.getHeader("id");
        return entityResult(appTabProjectService.selectAttachmentVideos(projectId,userId),"项目视频");
    }
}